// pages/fill/chooseMajor/chooseMajor.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    screenHeight: app.globalData.screenHeight,
    currentIndex: 0,
    multipleContent1: '专业',
    majorList: [],
    majorConfrim: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMajorType()
    this.getAreaList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
   
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  chooseMajor(e) {
    let that = this;
    let majorList = that.data.majorList;
    let currentIndex = e.currentTarget.dataset.index;
    // console.log(currentIndex);
    // console.log(majorList[currentIndex]);
    if(!majorList[currentIndex].type ){
      majorList[currentIndex].type = 'choosed' ;
    }else {
      majorList[currentIndex].type = ''
    }

    this.setData({
      majorList: majorList
    })
  },
  chooseAddress(e){
    let that = this;
    let addressList = that.data.addressList;
    let currentIndex = e.currentTarget.dataset.index;
    if(!addressList[currentIndex].type ){
      addressList[currentIndex].type = 'choosed' ;
    }else {
      addressList[currentIndex].type = ''
    }
    this.setData({
      addressList: addressList
    })
  },
  getMajorType() {
    app.globalData.wxRequest.requestGet('major/getMajorType.do').then(res => {
      if (res.code == '201') {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
        return
      }
      let majorListData = res.data;
      majorListData.map(item=>{
        item.type = ''
      })
      this.setData({
        majorList: majorListData
      })
    })
  },
  getAreaList(){
    let that = this
    app.globalData.wxRequest.customRequest('common/getAreaList.do', "GET", {}).then(res => {
      if (res.code == '201') {
        wx.showToast({
          title: res.msg,
          icon: 'error'
        })
        return
      }
      that.setData({
        addressList: res.data
      })
    })
  },
  hidecertificates(){
    const { majorList,addressList} = this.data
    let chooseList = {}
     chooseList.majorList = majorList.filter(item=>item.type === 'choosed')
     chooseList.addressList = addressList.filter(item=>item.type === 'choosed')
    wx.redirectTo({
      url: `/pages/fill/volunteerList/volunteerList?chooseList=${JSON.stringify(chooseList)}`,
    })
  }
})